package com.mall.controller;


import com.mall.pageResult.PageResult;
import com.mall.dto.OmsOrderDto;
import com.mall.pojo.OmsOrderDeliveryParam;
import com.mall.pojo.OmsOrder;
import com.mall.pojo.OmsReceiverInfoParam;
import com.mall.service.OmsOrderService;
import com.mall.utils.Result;
import com.mall.vo.OmsOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OmsOrderController {
    @Autowired
    private OmsOrderService orderService;


    /**
     * 修改用户订单信息
     * @param receiverInfoParam
     * @return
     */
    @PostMapping("/update/receiverInfo")
    public Result<Integer> updateReceiverInfo(@RequestBody OmsReceiverInfoParam receiverInfoParam ){
        //调用方法进行修改
        Integer updateNum = orderService.updateReceiverInfo(receiverInfoParam);

        return Result.success(updateNum,"操作成功");


    }



    /**
     * 批量发货
     * @param deliveryParamList
     * @return
     */

    @PostMapping("/update/delivery")
    public Result<Integer> updateDeliveryByIds(@RequestBody List<OmsOrderDeliveryParam> deliveryParamList){
        //调用方法进行修改
        Integer updateNum = orderService.updateDeliveryByIds(deliveryParamList);


        return Result.success(updateNum,"操作成功");



    }



    /**
     * 备注订单
     * @param id
     * @param note
     * @param status
     * @return
     */
    @PostMapping("/update/note")
    public Result<Integer> updateNoteById(@RequestParam(value = "id") Long id,
                                          @RequestParam(value = "note") String note,
                                          @RequestParam(value = "status") Integer status){
        //调用方法进行修改
        Integer updateNum = orderService.updateNoteById(id,note,status);

        return Result.success(updateNum,"操作成功");


    }

    /**
     * 根据id查看详情信息
     * @param id
     * @return
     */

@GetMapping("/{id}")
public Result<OmsOrderVo> findOrderById(@PathVariable Integer id){
    //调用方法进行查询
    OmsOrderVo omsOrderVo=orderService.findOrderById(id);

    return Result.success(omsOrderVo,"操作成功");
}

/**
 * 批量关闭订单

 */
@PostMapping("/update/close")
public Result<Integer> closeOrder(@RequestParam(value = "ids") List<Integer> ids,
                                  @RequestParam(value = "note") String note){
    //调用方法进行修改订单状态
    Integer updateNum = orderService.updateCloseStatus(ids,note);
    //返回参数
    return Result.success(updateNum,"操作成功");

}




    /**
     * 批量删除订单
     * @return
     */
    @PostMapping("/delete")
    public Result<Integer> delteOrder(@RequestParam("ids") List<Integer> ids){
        //调用方法删除
        Integer deleteNum = orderService.deleteOrder(ids);

        return Result.success(deleteNum,"操作成功");

    }
    /**
     * 分页查询
     */
    @GetMapping("/list")
    public Result<PageResult<OmsOrder>> list(@RequestParam(value = "createTime",required = false) String createTime,
                                             @RequestParam(value = "orderSn",required = false) String orderSn,
                                             @RequestParam(value = "orderType",required = false) Integer orderType,
                                             @RequestParam(value = "pageNum",required = false) Integer pageNum,
                                             @RequestParam(value = "pageSize",required = false) Integer pageSize,
                                             @RequestParam(value = "receiverKeyWord",required = false) String receiverKeyWord,
                                             @RequestParam(value = "sourceType",required = false) Integer sourceType,
                                             @RequestParam(value = "status",required = false) Integer status) {
            //封装数据
            OmsOrderDto ooD = new OmsOrderDto();

            ooD.setCreateTime(createTime);
            ooD.setOrderSn(orderSn);
            ooD.setOrderType(orderType);
            ooD.setPageNum(pageNum);
            ooD.setPageSize(pageSize);
            ooD.setReceiverKeyWord(receiverKeyWord);
            ooD.setSourceType(sourceType);
            ooD.setStatus(status);

            //调用方法进行查询
            PageResult<OmsOrder> pageResult = orderService.omsOrderPage(ooD);
            return Result.success(pageResult, "操作成功");
    }
}
